#include "ResourceFactory.h"
#include "Texture.h"
#include "ResourcePtr.h"
#include "RenderPack.h"


namespace Display
{
	ResourceFactory::ResourceFactory(void)
	{
		pool = nullptr;
	}


	ResourceFactory::~ResourceFactory(void)
	{
		ResourcePool::Destroy(pool);
	}

	ResourceFactory * ResourceFactory::Create(ID3D11Device * device)
	{
		ResourceFactory * factory = new ResourceFactory();
		factory->SetDevice(device);
		factory->pool = ResourcePool::Create(device);

		return factory;
	}

	void ResourceFactory::Destroy(ResourceFactory * factory)
	{
		if(factory != nullptr)
		{
			delete factory;
			factory = nullptr;
		}
	}

	ResourcePtr * ResourceFactory::LoadTextureFromFile(std::string fileName)
	{
		if(pool->TextureExist(fileName))
		{
			return pool->AllocateTexture(fileName);
		}
		else 
		{
			ResourcePtr * ptr = pool->AllocateTexture(fileName);
			Texture * tex = (Texture*)ptr->Get();

			tex->LoadFromFile(fileName);
			return ptr;
		}
	}


	RenderPack * ResourceFactory::LoadRenderPackFromFile(std::string fileName)
	{
		//RenderPack * pack = RenderPack::Create(GetDevice());
		//to do
		
		return nullptr;


	}
}